/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

/**
 *
 * @author SDOG
 */
import com.mysql.jdbc.Statement;
import entity.PerfilesEntity;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
/**
* Clase que permite conectar con la base de datos
* @author alejo
*/
public class TipoclientesModel {
    
    
    public ArrayList listPER() throws SQLException {
        Statement stm;
        Conect cnx = new Conect();
        PreparedStatement pstm = null;
        stm = (Statement) cnx.getConnection().createStatement();
        String seleccion = "SELECT * FROM perfiles";
        pstm = cnx.getConnection().prepareStatement(seleccion);
        ArrayList<PerfilesEntity> ls = new ArrayList<>();
        ResultSet rs = pstm.executeQuery();
        PerfilesEntity obj = new PerfilesEntity(); 
        
        while(rs.next()){
            
            //datos de la tabla
            obj.setPER_PK((rs.getString("PER_PK")));
            obj.setPER_NOMBRE(rs.getString("PER_NOMBRE"));
            obj.setPER_DESCRIPCION(rs.getString("PER_DESCRIPCION"));//nombre es el campo de la base de datos
            ls.add(obj);
            
        }
        
        return ls;
    }
    
    
    public PerfilesEntity findPER(String PER_PK, String PER_NOMBRE) throws SQLException {
        
        Statement stm;
        Conect cnx = new Conect();
        PreparedStatement pstm = null;
        stm = (Statement) cnx.getConnection().createStatement();
        String seleccion = "SELECT * FROM Perfiles";
        pstm = cnx.getConnection().prepareStatement(seleccion);
        ArrayList<String> ls = new ArrayList<>();
        ResultSet rs = pstm.executeQuery();
        PerfilesEntity obj = new PerfilesEntity();
        
        while(rs.next()){
            //datos de la tabla
            if ((PER_PK.equals(rs.getString("PER_PK"))) || (PER_NOMBRE.equals(rs.getString("PER_NOMBRE")))){
            obj.setPER_PK(rs.getString("PER_PK"));
            obj.setPER_NOMBRE((rs.getString("PER_NOMBRE")));//nombre es el campo de la base de datos
            obj.setPER_DESCRIPCION(rs.getString("PER_DESCRIPCION"));
            }
            
        }
        
        return obj;
    
    }
    
    public void  editPER(PerfilesEntity obj) throws SQLException {
        
        Statement stm;
        Conect cnx = new Conect();
        PreparedStatement pstm = null;
        stm = (Statement) cnx.getConnection().createStatement();
        String seleccion = "update perfiles set perfiles.PER_NOMBRE="+obj.getPER_NOMBRE()+",perfiles.PER_DESCRIPCION="+obj.getPER_DESCRIPCION()+" where perfiles.PER_PK ="+obj.getPER_PK()+"";
        pstm = cnx.getConnection().prepareStatement(seleccion);
            
    }
    
    public void  EliminarPER(PerfilesEntity obj) throws SQLException {
        
        Statement stm;
        Conect cnx = new Conect();
        PreparedStatement pstm = null;
        stm = (Statement) cnx.getConnection().createStatement();
        String seleccion = "delete from perfiles  where perfiles.PER_PK ="+obj.getPER_PK()+"";
        pstm = cnx.getConnection().prepareStatement(seleccion);
            
    }
    
}

